﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>编辑 到货通知单</title>
    <link href="//unpkg.com/layui@2.9.21-rc.3/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <h2>编辑到货通知单</h2>
    <br />
    <br />
    <form>
        <!-- 通知单编号 -->
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span><b>通知单编号</b></label>
            <div class="layui-input-inline">
                <input style="width:190px" type="text" id="arrivalNoticeNode" name="arrivalNoticeNode" lay-verify="required" placeholder="请输入通知单编号" autocomplete="off" class="layui-input">
                <div class="layui-input-suffix">
                    <div class="layui-input-inline">
                        <div class="layui-input-group">
                            <button style="left:30px" type="button" class="layui-btn layui-btn-primary layui-btn-xs" onclick="arrivalAlls()">自动生成</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

            <!-- 通知单名称 -->
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color:red">*</span><b>通知单名称</b></label>
                <div class="layui-input-inline" style="width:500px">
                    <input type="text" id="arrivalNoticeName" name="arrivalNoticeName" lay-verify="required" placeholder="请输入通知单名称" autocomplete="off" class="layui-input">
                </div>
            </div>

            <!-- 采购订单编号 -->
            <div class="layui-form-item">
                <label class="layui-form-label"><b>采购订单编号</b></label>
                <div class="layui-input-inline" style="width:500px">
                    <input type="text" id="purchaseIndentId" name="purchaseIndentId" lay-verify="required" placeholder="请输入采购订单编号" autocomplete="off" class="layui-input">
                </div>
            </div>

            <!-- 供应商 -->
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color:red">*</span><b>供应商</b></label>
                <div class="layui-input-group">
                    <input type="text" id="supplierName" name="supplierName" placeholder="请选择供应商" class="layui-input">
                    <div class="layui-input-split layui-input-suffix" style="cursor: pointer;">
                        <i class="layui-icon layui-icon-search" lay-on="test-page"></i>
                    </div>
                </div>
            </div>

            <!-- 到货日期 -->
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color:red">*</span><b>到货日期</b></label>
                <div class="layui-input-inline">
                    @* <input type="text" name="pickingTime" class="layui-input" id="ID-laydate-type-datetime"  > *@
                    <input type="text" name="arrivalNoticeTime" id="ID-laydate-type-datetime" lay-verify="date" placeholder="请选择到货日期" autocomplete="off" class="layui-input">
                </div>
            </div>

            <!-- 联系人 -->
            <div class="layui-form-item">
                <label class="layui-form-label"><b>联系人</b></label>
                <div class="layui-input-inline" style="width:500px">
                    <input type="text" id="phoneName" name="phoneName" lay-verify="required" placeholder="请输入联系人" autocomplete="off" class="layui-input">
                </div>
            </div>

            <!-- 联系方式 -->
            <div class="layui-form-item">
                <label class="layui-form-label"><b>联系方式</b></label>
                <div class="layui-input-inline" style="width:500px">
                    <input type="text" id="phone" name="phone" lay-verify="required" placeholder="请输入联系方式" autocomplete="off" class="layui-input">
                </div>
            </div>

            <!-- 备注 -->
            <div class="layui-form-item">
                <label style="right:10px" class="layui-form-label"><b>备注</b></label>
                <div class="layui-input-inline" style="width:600px">
                    <textarea name="remark" id="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>

            <!-- 按钮 -->
            <div class="layui-form-item" style="left:570px">
                <div class="layui-btn-container">
                    <button type="button" class="layui-btn layui-bg-blue" lay-submit lay-filter="demo1">编辑</button>
                    <button type="button" class="layui-btn ">取消</button>
                </div>
            </div>
    </form>
    <br />
    <br />
    <div style="left:500px"><h3> ------------------------------------------------------------------------------------------------------  物料信息  ------------------------------------------------------------------------------------------------------</h3></div>
    <div class="layui-panel">
        <br />
        <!-- 按钮: 新增 修改 删除 -->
        <div>
            <button class="layui-btn layui-btn-primary layui-border-blue" onclick="addes()">+新增</button>
            <button class="layui-btn layui-btn-primary layui-border-green">修改</button>
            <button class="layui-btn layui-btn-primary layui-border-red">删除</button>
        </div>
        <!-- 表格 -->
        <div style="padding: 32px;">
            <table class="layui-table">
                <colgroup>
                    <col width="150">
                    <col width="150">
                    <col width="150">
                    <col width="150">
                    <col width="150">
                    <col width="150">
   @*                  <col width="150">
                    <col width="150"> *@
                    <col width="150">
                    <col>
                </colgroup>
                <thead>
                    <tr>
                        <th style="text-align:center">物料编码</th>
                        <th style="text-align:center">物料名称</th>
                        <th style="text-align:center">规格型号</th>
                        <th style="text-align:center">单位</th>
                        <th style="text-align:center">到货数量</th>
                        <th style="text-align:center">是否检验</th>
         @*                <th style="text-align:center">合格数量</th>
                        <th style="text-align:center">检验单号</th> *@
                        <th style="text-align:center">备注</th>
                    </tr>
                </thead>
                <tbody style="text-align:center">
                </tbody>
            </table>
            <div id="demo-laypage-all"></div>
        </div>
    </div>

    <!-- HTML Content -->
    <script src="//unpkg.com/layui@2.9.21-rc.3/dist/layui.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        layui.use(['form', 'laydate', 'util'], function () {
            var $ = layui.$;
            var form = layui.form;
            var layer = layui.layer;
            var laypage = layui.laypage;
            var laydate = layui.laydate;
            var table = layui.table;
            var util = layui.util;

            //就绪函数
            $(function () {
                ArrivalEdit(); //反填
            })

            //供应商
            util.on('lay-on', {
                'test-page': function () {
                    layer.open({
                        type: 1,
                        area: '100%',
                        resize: false,
                        shadeClose: true,
                        title: '供应商选择',
                        content: `
                                             <form class="layui-form" action="">
                                <div class="layui-form">
                                    <div class="layui-form-item">
                                        <div class="layui-input-group">
                                            <div class="layui-input-prefix">
                                                供应商编码
                                            </div>
                                            <div>
                                                <input id="supplierNo" type="text" placeholder="请输入供应商编码" class="layui-input">
                                            </div>

                                            <div class="layui-input-prefix" style="left:50px">
                                                供应商名称
                                            </div>
                                            <div style="left:50px">
                                                <input id="supplierName" type="text" placeholder="请输入供应商名称" class="layui-input">
                                            </div>

                                            <div class="layui-input-prefix" style="left:100px">
                                                供应商简称
                                            </div>
                                            <div style="left:100px">
                                                <input id="supplierShort" type="text" placeholder="请输入供应商简称" class="layui-input">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <div class="layui-input-group">
                                            <div class="layui-input-prefix" style="left:14px">
                                                英文名称
                                            </div>
                                            <dic style="left:14px">
                                                <input id="supplierEnglishName" type="text" placeholder="请输入供应商英文名称" class="layui-input">
                                            </dic>

                                            <div class="layui-input-prefix" style="left:77px">
                                                是否启用
                                            </div>
                                            <div style="left:77px;width:197px">
                                                <select id="supplierIsNo" lay-filter="testSelect">
                                                    <option value="-1">是否启用</option>
                                                    <option value="0">禁用</option>
                                                    <option value="1">启用</option>
                                                </select>
                                            </div>

                                            <div style="left:150px">
                                                <button onclick="ShowSupplier()" id="searchBtn" type="button" class="layui-btn layui-btn-normal">搜索</button>

                                            </div>

                                            <div style="left:170px">
                                                <button onclick="Break()" type="button" class="layui-btn layui-btn-primary">重置</button>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <div class="layui-input-group">
                                            <div>
                                                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-border-blue" lay-on="test-page-custom">
                                                    <i class="layui-icon layui-icon-add-1">新增</i>
                                                </button>
                                            </div>
                                        </div>
                                    </div>

                                    <table style="left:320px" class="layui-table">
                                        <thead>
                                            <tr>
                                                <td><input type="checkbox" name="check" onclick="checkAll()" /></td>
                                                <td>供应商编码</td>
                                                <td>供应商名称</td>
                                                <td>供应商简称</td>
                                                <td>供应商等级</td>
                                                <td>供应商评分</td>
                                                <td>供应商电话</td>
                                                <td>是否启用</td>
                                                <td>备注</td>
                                                <td>操作</td>
                                            </tr>
                                        </thead>
                                        <tbody></tbody>
                                    </table>
                                    <div id="demo-laypage-all"></div>
                                </div>
                            </form>
                                    `,
                        //success
                        success: function () {
                            var pageIndex = 1;
                            var pageSize = 2;

                            $(function () {
                                ShowSupplier(pageIndex, pageSize);
                            })
                            // 获取供应商编码
                            $('#searchBtn').click(function () {
                                var supplier = $('#supplierNo').val();
                                ShowSupplier(pageIndex, pageSize)
                            });
                            // 获取供应商名称
                            $('#searchBtn').click(function () {
                                var supplier1 = $('#supplierName').val();
                                ShowSupplier(pageIndex, pageSize)
                            });
                            //供应商简称
                            $('#searchBtn').click(function () {
                                var supplier2 = $('#supplierShort').val();
                                ShowSupplier(pageIndex, pageSize)
                            });
                            // 英文名称
                            $('#searchBtn').click(function () {
                                var supplier2 = $('#supplierEnglishName').val();
                                ShowSupplier(pageIndex, pageSize)
                            });
                            //是否启用
                            form.on('select(testSelect)', function (data) {
                                ShowPermission(data.value); // data.value
                            });
                            //供应商管理列表
                            function ShowSupplier(index, size) {
                                var supplierNo = $("#supplierNo").val() || "";
                                var supplierName = $("#supplierName").val() || "";
                                var supplierShort = $("#supplierShort").val() || "";
                                var supplierEnglishName = $("#supplierEnglishName").val() || "";
                                var supplierIsNo = $("#supplierIsNo").val() || -1;
                                $.ajax({
                                    url: '@ViewBag.FoundationRead' + "/api/UserLi/SearchSupplier",
                                    data: JSON.stringify({ supplierNo: supplierNo, supplierName: supplierName, supplierShort: supplierShort, supplierEnglishName: supplierEnglishName, supplierIsNo: supplierIsNo, pageIndex: index, pageSize: size }),
                                    type: "post",
                                    async: false,
                                    dataType: "json",
                                    contentType: "application/json",
                                    success: res => {
                                        var tbody = $("tbody");
                                        tbody.empty();
                                        if (res.data != null) {
                                            $.each(res.data, function () {
                                                tbody.append(`
                                                                    <tr>
                                                                        <td><input type="checkbox" class="check" value="${this.supplierId}" onclick="checkfan()" /></td>
                                                                        <td>${this.supplierNo}</td>
                                                                        <td>${this.supplierName}</td>
                                                                        <td>${this.supplierShort}</td>
                                                                        <td>${this.supplierClassName}</td>
                                                                        <td>${this.supplieScore}</td>
                                                                        <td>${this.supplierPhone}</td>
                                                                        <td>${this.supplierIsNo === 1 ? '启用' : '禁用'}</td>
                                                                        <td>${this.supplierRemark}</td>
                                                                        <td><a onclick="Dass('${this.supplierName}')" class="btn btn-link">选择</a></td>
                                                                    </tr>`);
                                            });
                                        }
                                        form.render(); // 重新渲染下拉框
                                        //完整显示
                                        laypage.render({
                                            elem: 'demo-laypage-all', // 元素 id
                                            count: res.totalCount, // 数据总数
                                            curr: index,//当前页
                                            limit: size,//每页几条
                                            limits: [2, 3, 4],
                                            layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                                            jump: function (obj, first) {
                                                if (!first) {
                                                    ShowSupplier(obj.curr, obj.limit);
                                                }
                                            }
                                        });
                                    }
                                })
                            }

                            // 对弹层中的表单进行初始化渲染
                            form.render();
                            // 表单提交事件
                            form.on('submit(demo-Search)', function (data) {
                                var field = data.field; // 获取表单字段值

                                // 显示填写结果，仅作演示用
                                // layer.alert(JSON.stringify(field), {
                                //     title: '当前填写的字段值'
                                // });
                                // 此处可执行 Ajax 等操作
                                // …

                                return false; // 阻止默认 form 跳转
                            });

                        }
                    })
                }
            })

            // 日期时间选择器
            laydate.render({
                elem: '#ID-laydate-type-datetime'
            });

            //到货通知 修改
            form.on('submit(demo1)', function (data) {
                //定义变量
                var datas = {
                    arrivalNoticeId: arrivalNoticeId,
                    arrivalNoticeNode: $("[name='arrivalNoticeNode']").val(), //通知单编号
                    arrivalNoticeName: $("[name='arrivalNoticeName']").val(), //通知单名称
                    purchaseIndentId: $("[name=purchaseIndentId]").val(), //采购订单编号
                    arrivalNoticeTime: $("[name=arrivalNoticeTime]").val(), //到货日期
                    phoneName: $("[name=phoneName]").val(), //联系人
                    phone: $("[name=phone]").val(), //联系方式
                    remark: $("[name=remark]").val(), //备注
                    supplierName: $("[name=supplierName]").val(), //供应商名称
                    documents: 1, //单据状态
                };
                console.log(datas);

                $.ajax({
                    url: '@ViewBag.FoundationWrite' + '/api/ProductType/ArrivalNoticesUpdates',
                    data: JSON.stringify(datas),
                    type: "post",
                    dataType: "json",
                    contentType: "application/json",
                    success: function (res) {
                        console.log(123, res);
                        if (res.code > 0) {
                            layer.alert('编辑成功!');
                            location.href = "/Messages/ArrivalNoticesList";
                        }
                        else {
                            alert('编辑失败!')
                        }
                    }
                })
                // layer.alert(JSON.stringify(field), {
                //     title: '当前填写的字段值'
                // });
                // 此处可执行 Ajax 等操作
                return false; // 阻止默认 form 跳转
            })

        });

        //自动生成 通知单编号
        function arrivalAlls() {
            var datec = new Date();
            var year = datec.getFullYear();
            var month = (datec.getMonth() + 1).toString().padStart(2, "0");
            var date = (datec.getDate() + 1).toString().padStart(2, "0");
            var hours = datec.getHours();
            var minute = (datec.getMinutes()).toString().padStart(2, "0");
            var seconds = (datec.getSeconds()).toString().padStart(2, "0");
            // var Encoding = "IF";
            var result = "AN" + year + month + date + hours + minute + seconds;
            console.log(result);
            $("#arrivalNoticeNode").val(result);
        };

        //反填通知单 数据
        var arrivalNoticeId = location.href.split("=")[1];
        function ArrivalEdit() {
            let obj = {
                arrivalNoticeId: arrivalNoticeId
            }
            console.log(obj);
            $.ajax({
                url: '@ViewBag.FoundationWrite' + "/api/ProductType/ArrivalNoticesEdits",
                data: JSON.stringify(obj),
                type: "post",
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    //反填表单数据
                    $("[name='arrivalNoticeNode']").val(res.objects.arrivalNoticeNode);
                    $("[name='arrivalNoticeName']").val(res.objects.arrivalNoticeName);
                    $("[name='purchaseIndentId']").val(res.objects.purchaseIndentId);
                    $("[name='supplierName']").val(res.objects.supplierName);
                    $("[name='arrivalNoticeTime']").val(res.objects.arrivalNoticeTime.split("T")[0]);
                    $("[name='phoneName']").val(res.objects.phoneName);
                    $("[name='phone']").val(res.objects.phone);
                    $("[name='remark']").val(res.objects.remark);
                }
            })
        }

        //反填 供应商
        function Dass(nameMC) {
            console.log(nameMC)
            $("[name='supplierName']").val(nameMC);
            layer.close(layer.index); // 关闭弹层
            // form.render(); // 重新渲染
        }

        //跳转到货通知单行 新增页面
        function addes(){
            layer.open({
                type: 2,
                title: '到货通知单行 新增',
                shadeClose: true,
                maxmin: true, //开启最大化最小化按钮
                area: ['100%', '100%'],
                content: '/Messages/NoticelinesAdd',
            });
            // location.href = "/Messages/";
        }

    </script>
</body>
</html>

<script>
    //物料信息
    var form = layui.form;
    var laypage = layui.laypage;
    var layer = layui.layer;
    var $ = layui.$;
    var laydate = layui.laydate;
    var util = layui.util;
    //分页
    var pageIndex = 1;
    var pageSize = 2;
    var arrivalNoticeNode = "";

    $(function () {
        RejectionLineList(1, 2);
    })

    // 搜索提交
    form.on('submit(demo-table-search)', function (data) {
        RejectionLineList(pageIndex, pageSize);
        return false; // 阻止默认 form 跳转
    });

    //物料信息显示
    function RejectionLineList(pageIndex, pageSize) {
        console.log(pageIndex, pageSize);
        $.post({
            url: '@ViewBag.FoundationWrite' + '/api/ProductType/NoticelinesLists',
            data: JSON.stringify({
                pageIndex: pageIndex,
                pageSize: pageSize,
                arrivalNoticeNode: $("#arrivalNoticeNode").val(),
            }),
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {

                var cont = ""; //定义变量
                console.log(res.data);
                $.each(res.data, function () {
                    cont += `<tr>
                      <td><b>${this.productManageNode}</b></span></td>
                      <td>${this.productManageName}</td>
                      <td>${this.productManageNumber}</td>
                      <td>${this.unites}</td>
                      <td>${this.noticeCount}</td>
                      <td>${this.isNo == 1 ? "是" : "否"}</td>
                      <td>${this.remarks}</td>
                    </tr>`
                })
                $("tbody").html(cont);
                console.log(res);
                // console.log(996, pageSize, pageIndex, res)
                // 完整显示
                laypage.render({
                    elem: 'demo-laypage-all', // 元素 id
                    count: res.totalCount, // 数据总数
                    curr: pageIndex,//当前页
                    limit: pageSize,//每页几条
                    limits: [1, 2, 3],
                    layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                    jump: function (obj, first) {
                        console.log(obj.curr);
                        console.log(obj.limit);
                        if (!first) {

                            RejectionLineList(obj.curr, obj.limit);
                        }
                    }
                });
            }
        });
    }


</script>
